#include <stdio.h>

void fillMatrix(int n, int matrix[20][20]) 
{
    int i, j, num = 1, direction = 1;
    for (int line = 1; line <= 2 * n - 1; ++line) 
    {
        int start_col = line <= n  ? 0 : line - n;
        int count = line <= n ? line : 2 * n - line;
        if (direction) 
        {
            i = line <= n ? line - 1 : n - 1;
            j = start_col;
            while (count--) 
            {
                matrix[i--][j++] = num++;
            }
        }
        else {
            j = line <= n ? line - 1 : n - 1;
            i = start_col;
            while (count--) 
            {
                matrix[i++][j--] = num++;
            }
        }
        direction = 1 - direction;
    }
}

void printMatrix(int n, int matrix[20][20]) 
{
    for (int i = 0; i < n; ++i) 
    {
        for (int j = 0; j < n; ++j) 
        {
            printf("%5d", matrix[i][j]);

        }
        printf("\n");
    }
}

int main() {
    int n;
    scanf("%d", &n);
    int matrix[20][20];
    fillMatrix(n, matrix);
    printMatrix(n, matrix);
    return 0;
}
